<template>
    <div class="refundDetail" v-loading="loading">
        <div class="refundorder">
            <div class="contents">
                <div class="orderNumber">
                    <div class="orderNubermessg">
                        <span class="iconFont"></span>
                        <strong>订单号：{{allData.ORDER_NO}}</strong>
                    </div>
                    <div class="ordermessage">
                        <p>
                            <span>用户：{{allData.PHONE}}</span>
                        </p>
                        <p>
                            <span v-if="allData.PAY_WAY==1">支付方式：微信支付</span>
                            <span v-else-if="allData.PAY_WAY==2">支付方式：支付宝支付</span>
                            <span v-else-if="allData.PAY_WAY==4">支付方式：线下支付</span>
                            <span v-else-if="allData.PAY_WAY==9">支付方式：银豹支付</span>
                            <span v-else>支付方式：其它支付</span>
                            <span>支付流水号:
                                <strong>{{allData.TRADENO}}</strong>
                            </span>
                        </p>
                        <p>
                            <span>操作时间：{{allData.LAST_UPDATE_TIME|filterTimess}}</span>
                            <span>操作人：{{allData.MASTER_NAME}}</span>
                        </p>
                    </div>
                </div>
                <div>
                    <div class="refundordertable">
                        <div style="text-align:right;">
                            <el-button @click.native="prints">打印订单</el-button>
                            <el-button v-if="allData.REFUND_STATUS!==1" @click.native="stops">终止退款</el-button>
                            <el-button v-if="allData.REFUND_STATUS!==1" style="color:#fff; background:#f40;" @click.native="ensures">确定退款</el-button>
                        </div>
                        <div class="refundmessage">
                            <div>
                                <span>状态</span>
                                <strong v-if="allData.REFUND_STATUS===0">待退款</strong>
                                <strong v-if="allData.REFUND_STATUS===1">已退款</strong>
                                <strong v-if="allData.REFUND_STATUS===2">已关闭</strong>
                            </div>
                            <div class="refundAmountR">
                                <span>退款金额</span>
                                <strong>￥{{allData.AMOUNT}}</strong>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="refundorder">
            <header>退款商品信息</header>
            <div class="refundList">
                <el-table :data="allData.ORDER_DETAIL_LIST" style="width: 100%; border-bottom:none;" header-row-class-name="labename">
                    <el-table-column prop="FIRST_CLASS_NAME" label="项目大类" width="200" label-class-name="labelname"> </el-table-column>
                    <el-table-column prop="SERV_NAME" label="商品名称" width="350"> </el-table-column>
                    <el-table-column prop="PRICE" label="销售价" width="200"> </el-table-column>
                    <el-table-column prop="PRICE" label="实付" width="200"> </el-table-column>
                    <el-table-column prop="QUANTITY" label="数量（件）" width="200"> </el-table-column>
                    <el-table-column prop="AMOUNT" label="小计" width="200"> </el-table-column>
                </el-table>
            </div>
        </div>
        <div class="refundorder">
            <div class="textfield">
                <span>退款备注:</span>
                <el-input v-if="allData.REFUND_STATUS===1" readonly type="textarea" :rows="10" placeholder="请输入该门店备注" v-model="allData.REMARK"> </el-input>
                <el-input v-else type="textarea" :rows="10" placeholder="请输入该门店备注" v-model="textarea1"> </el-input>
            </div>
            <div class="textfield">
                <span>取消备注:</span>
                <el-input readonly type="textarea" :rows="10" placeholder="请输入该门店备注" v-model="allData.APPLICATION"> </el-input>
            </div>
        </div>
    </div>
</template>
<script>
    import { setCookie, getCookie } from '@/assets/js/cookie'
    export default {
        name: 'refund_detail',
        data() {
            return {
                textarea1: '', //退款备注                                
                loading: true,
                allData: '', //退款详情数据
            }
        },
        created() {
            this.getD();
        },
        methods: {
            //退款详情
            getD() {
                this.$axiosPost('/4SCAFE/userRefundAuditSystem/getCafeUserRefundAuditDetail.action', {
                    REFUND_ID: this.$route.params.id
                }).then(res => {
                    //console.log(res);
                    this.loading = true;
                    if(res.STATUS_CODE === 1) {
                        this.loading = false;
                        this.allData = res;
                    }
                })
            },
            //打印清单
            prints() {
                window.print();
            },
            //终止退款
            stops() {
                let that = this;
                this.$confirm('此操作不可逆, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    that.OK1();
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            },
            //确定退款
            ensures() {
                let that = this;
                this.$confirm('此操作不可逆, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    that.OK2();
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            },
            //二次终止退款
            OK1() {
                let obj = {};
                obj.REFUND_ID = +this.allData.REFUND_ID;
                obj.REMARK = this.allData.APPLICATION;
                obj.MASTER_NAME = getCookie('userName');
                let flagss = true;
                if(!flagss) {
                    return;
                }
                this.$axiosPost('/4SCAFE/userRefundAuditSystem/endRefund.action', obj).then(res => {
                    flagss = false;
                    //console.log(res);
                    if(res.STATUS_CODE === 1) {
                        flagss = true;
                        this.$message({
                            type: 'success',
                            message: '终止退款成功'
                        });
                        setTimeout(() => this.$router.push({
                            path: '/manages/refund'
                        }), 1500);
                    } else if(res.STATUS_CODE === 15) {
                        this.$message({
                            type: 'warning',
                            message: '订单号无效'
                        });
                    }
                })
            },
            //二次确定退款
            OK2() {
                if(this.textarea1 == '') {
                    this.$alert('请输入退款备注', '提示', {
                        confirmButtonText: '确定',
                    });
                    return;
                }
                let obj = {};
                obj.REFUND_ID = +this.allData.REFUND_ID;
                obj.REMARK = this.textarea1;
                obj.MASTER_NAME = getCookie('userName');
                let flagss = true;
                if(!flagss) {
                    return;
                }
                this.$axiosPost('/4SCAFE/userRefundAuditSystem/verifyRefund.action', obj).then(res => {
                    console.log(res);
                    flagss = false;
                    if(res.STATUS_CODE === 1) {
                        flagss = true;
                        this.$message({
                            type: 'success',
                            message: '确认退款成功'
                        });
                        setTimeout(() => this.$router.push({
                            path: '/manages/refund'
                        }), 1500);
                    }
                })
            },            
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .refundorder {
        width: 97%;
        margin: 25px auto;
        background: #fff;
        .contents {
            display: flex;
            justify-content: space-between;
            .orderNumber {
                padding: 30px 0 20px 20px;
                .orderNubermessg {
                    .iconFont {
                        display: inline-block;
                        width: 26px;
                        height: 26px;
                        background: #f40;
                        border-radius: 50%;
                    }
                    strong {
                        display: inline-block;
                        height: 26px;
                        color: #000;
                        font-size: 26px;
                        line-height: 26px;
                        margin-left: 10px;
                    }
                }
                .ordermessage {
                    padding: 10px 38px;
                    p {
                        span {
                            display: inline-block;
                            width: 350px;
                            strong {
                                font-weight: 100;
                                color: blue;
                            }
                        }
                    }
                }
            }
            .refundordertable {
                padding: 30px 10px 0 10px;
                .refundmessage {
                    display: flex;
                    justify-content: flex-end;
                    margin-top: 20px;
                    div {
                        display: flex;
                        flex-flow: column;
                        justify-content: flex-end;
                        width: 200px;
                        span {
                            display: flex;
                            justify-content: flex-end;
                            margin-bottom: 10px;
                            color: #ccc;
                            font-size: 12px;
                        }
                        strong {
                            margin-top: 5px;
                            display: flex;
                            justify-content: flex-end;
                            font-size: 20px;
                        }
                    }
                    .refundAmountR {
                        margin-right: 40px;
                    }
                }
            }
        }
        header {
            padding: 30px 20px;
            font-weight: 700;
            font-size: 16px;
        }
        .refundList {
            padding: 20px 20px;
        }
        .textfield {
            display: flex;
            padding: 40px 300px 0 300px;
            span {
                width: 100px;
            }
        }
    }
</style>